Factor out the parsing of XAUTHORITY, so that it can be used by the unit test,
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Thu, 6 Apr 2006 13:22:52 +0000 (14:22 +0100)
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Thu, 6 Apr 2006 13:22:52 +0000 (14:22 +0100)
and fix that test to use it.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xm/create.py
tools/python/xen/xm/tests/test_create.py

index 6da9ed37113ae9f059009090491227454d27e41b..8c3be846bd723ca1293a0088da4fff2cd863d7cc 100644 (file)
@@ -850,6 +850,18 @@ def make_domain(opts, config):
     opts.info("Started domain %s" % (dom))
     return int(sxp.child_value(dominfo, 'domid'))
 
+
+def get_xauthority():
+    xauth = os.getenv("XAUTHORITY")
+    if not xauth:
+        home = os.getenv("HOME")
+        if not home:
+            import posix, pwd
+            home = pwd.getpwuid(posix.getuid())[5]
+        xauth = home + "/.Xauthority"
+    return xauth
+
+
 def parseCommandLine(argv):
     gopts.reset()
     args = gopts.parse(argv)
@@ -864,14 +876,7 @@ def parseCommandLine(argv):
         gopts.vals.display = os.getenv("DISPLAY")
 
     if not gopts.vals.xauthority:
-        xauth = os.getenv("XAUTHORITY")
-        if not xauth:
-            home = os.getenv("HOME")
-            if not home:
-                import posix, pwd
-                home = pwd.getpwuid(posix.getuid())[5]
-            xauth = home + "/.Xauthority"
-        gopts.vals.xauthority = xauth
+        gopts.vals.xauthority = get_xauthority()
 
     # Process remaining args as config variables.
     for arg in args:
index 4cce721ea077a282dd4ab2358bd74998b0b0ba3c..7bbe7098349c9e738993b50e0b28e9a828d775db 100644 (file)
@@ -51,6 +51,7 @@ class test_create(unittest.TestCase):
                  'path'      : '.:/etc/xen',
                  'builder'   : 'linux',
                  'nics'      : -1,
+                 'xauthority': xen.xm.create.get_xauthority(),
                  })
 
 
@@ -99,6 +100,8 @@ on_crash    = 'destroy'
                  'interface'   : 'eth0',
                  'path'        : '.:/etc/xen',
                  'builder'     : 'linux',
+
+                 'xauthority'  : xen.xm.create.get_xauthority(),
                })
 
 
@@ -138,6 +141,8 @@ cpu_weight = 0.75
                  'path'       : '.:/etc/xen',
                  'builder'    : 'linux',
                  'nics'       : -1,
+
+                 'xauthority' : xen.xm.create.get_xauthority(),
                  })
             
 
@@ -188,6 +193,8 @@ ne2000=0
                  'dhcp'        : 'off',
                  'interface'   : 'eth0',
                  'path'        : '.:/etc/xen',
+
+                 'xauthority'  : xen.xm.create.get_xauthority(),
                })